package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.SalesPlanDTO;
import com.lyf.scm.admin.api.dto.SalesPlanInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *      需求计划
 * @author: haodong
 * @data: 2020/8/7 17:27
 */
@Service
@Slf4j
public class SalesPlanFacade {

    @Resource
    private SalesPlanRemote salesPlanRemote;

    /**
     * 按条件查询需求计划
     * @param salesPlanDTO
     * @return
     */
    public PageInfo<SalesPlanInfoDTO> listWeekBySelective(SalesPlanDTO salesPlanDTO) {
        log.info("需求计划明细信息入参:demandPlan:{}", JSON.toJSONString(salesPlanDTO));
        Response<PageInfo<SalesPlanInfoDTO>> response = salesPlanRemote.listWeekBySelective(salesPlanDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public List<SalesPlanInfoDTO> listAllByCycles(SalesPlanDTO demandPlan) {
        log.info("需求计划指标入参:demandPlan:{}",demandPlan);
        Response<List<SalesPlanInfoDTO>> response = salesPlanRemote.listAllByCycles(demandPlan);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public feign.Response exportExcel(SalesPlanDTO salesPlanDTO, Integer type) {
        log.info("销售计划导出excel入参:salesPlanDTO:{}，type:{}", JSON.toJSONString(salesPlanDTO),type);
        return salesPlanRemote.exportExcel(salesPlanDTO, type);
    }

    public void delete(String opSign) {
        log.info("删除需求计划:{}", JSON.toJSONString(opSign));
        salesPlanRemote.delete(opSign);
    }
}
